/***/
var glinks = [];
var gindex = 0;
function judgeNumber(obj){
	if(isNaN(obj.value)){
		obj.value="0";		
	}else
		return ;
}
/**
 * 将对象转换为字符串类型
 */

function parseString(value) {
    if (value == null) {    
        return "";    
     } else {    
        return value.toString();    
     }    
}
/**
 * 对日期进行格式化，
 * 
 * @param date
 *            要格式化的日期
 * @param pattern
 *            进行格式化的模式 支持的模式字母有： y:年, M:年中的月份(1-12), d:月份中的天(1-31), H:小时(0-23),
 *            h:小时(0-12), m:分(0-59), s:秒(0-59), S:毫秒(0-999), E:星期(以汉语表示),
 *            e:星期(以英文表示), A:上午/下午标识, a:AM/PM标识
 * @return
 */   
function formatDate(date,pattern){    
    var d;    
    if((d=parseDate(date))==null){    
        return "";    
     }    
    if(!pattern){    
         pattern = "yyyy-MM-dd";    
     }    
    var arrWeek = ["星期日","星期一","星期二","星期三","星期四","星期五","星期六","Sunday","Monday","Tuesday","Tuesday","Thursday","Friday","Saturday"];    
    var value = new Object();    
     value["y"] = parseString(d.getFullYear());    
     value["M"] = parseString(d.getMonth() + 1);    
     value["d"] = parseString(d.getDate());    
     value["H"] = parseString(d.getHours());    
     value["h"] = parseString(value["H"] > 12 ? (value["H"]-12) : value["H"]);    
     value["m"] = parseString(d.getMinutes());    
     value["s"] = parseString(d.getSeconds());    
     value["S"] = parseString(d.getMilliseconds());    
     value["E"] = arrWeek[d.getDay()];    
     value["e"] = arrWeek[d.getDay() + 7];    
     value["a"] = (value["H"] > 12 ? "PM" : "AM");    
     value["A"] = (value["H"] > 12 ? "下午" : "上午");    
    var result = "";    
    var i = 0;    
    var hasE = false;// 是否出现过星期
    var hasAMPM = false;// 是否出现过上午下午
    while(i < pattern.length){    
        var c = pattern.charAt(i++);    
        var lc = c;// 记录本次要处理的字母,如'y'
        var tmpStr = c;// 本次在处理的字母格式,如'yyyy'
        while(i < pattern.length && (c=pattern.charAt(i))==lc){    
             tmpStr += c;    
             i++;    
         }    
        if(value[lc]!=""&&value[lc]!=null&&value[lc]!="undefined"){    
            // 本次要处理的字母是模式母
            if((lc == "E" || lc == "e") && !hasE){    
                // 星期
                 result += value[lc];    
                 hasE = true;    
             } else if(lc == "E" || lc == "e") {    
                 result += tmpStr;    
             } else if((lc=="a" || lc == "A")   && !hasAMPM){    
                // 上下午
                 result += value[lc];    
                 hasAMPM = true;    
             } else if((lc=="a" || lc == "A") ){    
                 result += tmpStr;    
             } else {    
                // 如果是 单个的日期，月份，小时，分，秒的字符串，不能再进行字符串的截取操作
                if(tmpStr == "d" || tmpStr == "M" || tmpStr=="H" || tmpStr=="h" || tmpStr == "m" || tmpStr == "s"){    
                     result += value[lc];    
                 } else {    
                     result += value[lc].fillChar(tmpStr.length);    
                 }    
             }    
         } else {// 非模式字母，直接输出
             result += tmpStr;    
         }    
     }    
    return result;    
} 

function parseDate(value) {    
    var date = null;    
    if (Date.prototype.isPrototypeOf(value)) {    
         date = value;    
     } else if (typeof (value) == "string") {    
         date = new Date(value.replace(/-/g, "/"));    
     } else if (value != null && value.getTime) {    
         date = new Date(value.getTime());    
     }    
     ;    
    return date;    
}
/** *扩展原型函数 */


String.prototype.fillChar = function(length,mode,char){    
    if(!char){
        char = "0";    
     }    
    if(this.length>length){// 比实际想要的长度更大
        if(mode=="after"){// 如果是要在后面填充，截取的时候会将会后面的部分截取掉
            return this.substr(0,length);    
         } else {// 默认截取前一部分的数据
            return this.substr(this.length - length,length);    
         }    
     }    
    var appendStr = "";    
    for(var i = 0; i < (length - this.length)/char.length;i++){    
         appendStr += char;    
     }    
    if(mode == "after"){    
        return this + appendStr;    
     }    
    else {    
        return appendStr + this;    
     }    
}
Array.prototype.insertAt = function( index, value ) {
	var part1 = this.slice( 0, index );         
	var part2 = this.slice( index );         
	part1.push( value );         
	return( part1.concat( part2 ) );     
	
};       
Array.prototype.removeAt = function( index ){
	var part1 = this.slice( 0, index );         
	var part2 = this.slice( index );         
	part1.pop();         
	return( part1.concat( part2 ) );     
	
} 
Array.prototype.concatAt = function (index,ary){
	var part1 = this.slice( 0, index );         
	var part2 = this.slice( index );         
	var temp = part1.concat(ary);         
	return( temp.concat( part2 ) );   
}

function test() {

}
function toJsonString(obj){
	return JSON.stringify(obj);
}
function getObjectText(obj) {
	var msg = '';
	for (key in obj) {
		msg += key + ' ===> ' + obj[key] + '\n';
	}
	return msg;
}

function debugObject(obj){
	  var d = $('#debug');
	  d.html(getObjectHtml(obj));
}
function getObjectHtml(obj) {
	var msg = '<span style="font-size:18px;">';
	for (key in obj) {
		msg += key
				+ '<b><span style="color:red;font-size:16px;"> ===> </span></b>'
				+ obj[key] + '<br/>';
	}
	msg += "</span>";
	return msg;
}

// system function
function doExtend(funcName) {
	try {
		if (typeof (eval(funcName)) == "function") {
			// alert("function is "+funcName);
			if (arguments.length == 1) {
				funcName();
			} else if (arguments.length == 2) {
				funcName(arguments[1]);
			}
		}

	} catch (e) {
		alert(e.message);

	}
}
function doAjaxPost(link,data){
	     $("#contentbody").empty();	    	
		$.ajax({
					type : "POST",
					url : link,
					data : $.param(data),
					scriptCharset:"utf-8",
					success : function(msg) {
						$("#contentbody").html(msg);
						pushLink(link,data);	
						//$.unblockUI();
					},
					start : function() {
						$("#contentbody")
								.html("<img src='"+sbase+"images/content-loading.gif'/>");
					},
					error : function(msg) {
						alert(trace(msg));
						$("#contentbody").html("<img src='"+sbase+"images/error.jpg'/><br/>"+msg);
					}
				});
}
function doPost(link,postData,callback){	
	  $("#contentbody").empty();
	  $("#contentbody").html("<img src='"+sbase+"images/content-loading.gif'/>'");
		$.ajax({
					type : "POST",
					url : link,
					data : postData,
					scriptCharset:"utf-8",
					success : function(msg) {
						$("#contentbody").html(msg);
						//$.unblockUI();
						doExtend(callback);
											
						
					},
					error : function(XMLHttpRequest, textStatus, errorThrown) {
						$("#contentbody").html("<em>发生错误，如果重新登录后如故，请报告管理员:69625</em> 错误信息如下： <hr/>"
								+errorThrown+"|"+textStatus);
					}
				});
}
function doSubmit(link,postData,callback){	
	$.ajax({
		type : "POST",
		url : link,
		data : postData,
		scriptCharset:"utf-8",
		success : function(msg) {
			doExtend(callback);
		},
		error : function(msg) {
			$("#contentbody").html(msg);
		}
	});
}
function doAction(url,data,call){
	
     $.ajax({
					type : "GET",
					url : url,
					data : data,
					scriptCharset:"utf-8",
					success : function(msg) {											
						//$.unblockUI();
						doExtend(call,msg);
					},
					error : function(msg) {
						alert("出现错误: "+msg);
						if(console)console.log(msg);
					}
				});
}
function doGet(url,data,call){	
	  $("#contentbody").empty();	  
		$("#contentbody").html("<img src='"+sbase+"images/content-loading.gif'/>'");
		$.ajax({
					type : "GET",
					url : url,
					data : data,
					scriptCharset:"utf-8",
					success : function(msg) {
						$("#contentbody").html(msg);					
						
					},
					error : function(XMLHttpRequest, textStatus, errorThrown) {
						$("#contentbody").html("<em>发生错误，如果重新登录后如故，请报告管理员:69625</em> 错误信息如下： <hr/>"
								+errorThrown+"|"+textStatus);
					}
				});
}
function doAjaxLink(link) {
	
    $("#contentbody").empty();   
	$("#contentbody").html("<img src='"+sbase+"images/content-loading.gif'/>'");
	var func = null;
	if(arguments.length==2)
		func = arguments[1];
	$.ajax({
				type : "GET",
				url : link,
				data : "",
				scriptCharset:"utf-8",
				success : function(msg) {
					$("#contentbody").html(msg);								
					doExtend(func);
				},
				start : function() {
					$("#contentbody")
							.html("<img src='"+sbase+"images/content-loading.gif'/>");
				},
				error : function(XMLHttpRequest, textStatus, errorThrown) {
					
					$("#contentbody").html(textStatus);
				}
			});
}

function doAjaxLinkById(link,id){
	$("#"+id).html("<img src='"+sbase+"images/content-loading.gif'/>'");
	$.ajax({
				type : "GET",
				url : link,
				data : "",
				scriptCharset:"utf-8",
				success : function(msg) {
					$("#"+id).html(msg);
				},
				start : function() {
					$("#"+id)
							.html("<img src='"+sbase+"images/content-loading.gif'/>");
				},
				error : function(msg) {
					$("#"+id).html("<img src='"+sbase+"images/error.jpg'/><br/>"+msg);
				}
			});
	
}
function doAjaxHole(link) {
	$("body").html("<img src='"+sbase+"images/content-loading.gif'/>'");
	$.ajax({
				type : "GET",
				url : link,
				data : "",
				success : function(msg) {
					$("body").html(msg);
				},
				start : function() {
					$("body")
							.html("<img src='"+sbase+"images/content-loading.gif'/>");
				},
				error : function(msg) {
					alert(trace(msg));
					$("body").html("<img src='"+sbase+"images/error.jpg'/><br/>"+msg);
				}
			});
}


function doAjaxLinkDebug(link) {
	$("#contentbody").html("<img src='"+sbase+"images/content-loading.gif'/>");
	$.ajax({
				type : "GET",
				url : link,
				data : "",
				success : function(msg) {
					$("#contentbody").html(msg);
					$("#debug").text("<br/>" + msg);
				},
				error : function(msg) {
					$("#debug").text("<br/>" + msg); 
				}
			});
}

function doAjaxEnsure(link, msg) {
	if (confirm(msg)) {
		doAjaxLink(link);
	} else {
		return false;
	}
}

function getAjaxLink(url, text) {
	var link = "<a href=\"javascript:;\" onclick=\"doAjaxLink(\'" + url
			+ "\');return false;\" >";
	link += text;
	link += "</a>";
	return link;
}

function getAjaxLinkDebug(url, text) {
	var link = "<a href=\"javascript:;\" onclick=\"doAjaxLinkDebug(\'" + url
			+ "\');return false;\" >";
	link += text;
	link += "</a>";
	return link;
}

function getAjaxMsgLink(url, text, msg) {
	var link = "<a href=\"javascript:;\" onclick=\"doAjaxEnsure(\'" + url
			+ "\',\'" + msg + "\');return false;\" >";
	link += "<img src='"+sbase+"images/removeme.gif' style='border:none'/>";
	link += "</a>";
	return link;
}

function getAjaxButton(url, text) {
	var link = "<button href=\"javascript:;\" onclick=\"doAjaxWindow(\'" + url
			+ "\');return false;\" >";
	link += text;
	link += "</button>";
	return link;
}
function doAjaxWindow(url) {
	var win;
	$.ajax({
				type : "POST",
				url : url,
				data : "",
				success : function(msg) {
					// $("#content").html(msg);

				},
				error : function(msg) {
					$("#contentbody").html("<img src='"+sbase+"images/error.jpg'/>'");
				}
			});
}
function trace(obj){
   var msg='';
   for(key in obj){
	   msg+=key+'===>'+obj[key]+'<br/>';
   }   
   return msg;
}
function isIE(){
   if(-[1,]){
     return false;
}else{
     return true;
}

}

function getEvent() { // 获取事件对象
	if (document.all)
		return window.event;
	func = getEvent.caller;
	while (func != null) {
		var arg0 = func.arguments[0];
		if (arg0) {
			if ((arg0.constructor == Event || arg0.constructor == MouseEvent)
					|| (typeof(arg0) == "object" && arg0.preventDefault && arg0.stopPropagation)) {
				return arg0;
			}
		}
		func = func.caller;
	}
	return null;
}
function stopDefault( e ) {
        // 阻止默认浏览器动作(W3C)
        if ( e && e.preventDefault )
            e.preventDefault();
        // IE中阻止函数器默认动作的方式
        else
            window.event.returnValue = false;
        return false;
}

function openWithMask(url){
     var e = getEvent();	
     stopDefault(e);
     $.nmManual(url);
}
function backstep(){
	if(gindex<0){
		gindex==0;
	}
	executeUrl(gindex);
	gindex--;
}
function redostep(){
   if(gindex>=glinks.length){
	   gindex = glinks.length-1;
   }
   executeUrl(gindex);
   gindex++;
}

function executeUrl(idx){
	var uobj = glinks[idx];
	if(uobj.param==null){
	       doAjaxLink(uobj.url);
	}else{
		   doAjaxPost(uobj.url,uobj.param);
	}	
}

function pushLink(url,param){
	glinks.push({"url":url,"param":typeof param!='undefined'?param:null});	
	gindex=glinks.length-1;
}
function createNotify(title, text) {
	jQuery.pnotify( {
		pnotify_title : title,
		pnotify_text : text,
		pnotify_hide : true,
		pnotify_type : 'error',
		pnotify_delay : 3000
	});
}


function createSticky(title, text) {
	jQuery.pnotify( {
		pnotify_title : title,
		pnotify_text : text,
		pnotify_hide : false,
		pnotify_type : 'error'
	});
}
/**
 * 根据元素类型创建form元素 <input type="text" /> <input type="checkbox" /> <input
 * type="radio" /> <input type="image" /> <input type="file" /> <input
 * type="submit" /> <input type="reset" /> <input type="password" /> <input
 * type="button" /> <select><option/></select> <textarea></textarea> 返回的是jq对象
 */
function elementByType(type){
	switch(type){
	case "select":
		var e = $("<select></select>");
		return e;
	case "label":
		var e = $("<label></label>");
		return e;
	case "textarea":
		return $("<textarea></textarea>");
		;
	case "img":
		return $("<img></img>");
		;
	default:
		return $("<input type='"+type+"' />");
		;
	}
}

// 释放IE内存
function releaseForIE()
{        
      if(!document.all) return;
      if(typeof (CollectGarbage)=='function')
	  {
	    CollectGarbage();
	    setTimeout("CollectGarbage();", 1);
	  }
}
// 获取元素的纵坐标
function getTop(e){ 
	var offset=e.offsetTop; 
	if(e.offsetParent!=null) offset+=getTop(e.offsetParent); 
	return offset; 
} 
// 获取元素的横坐标
function getLeft(e){ 
	var offset=e.offsetLeft; 
	if(e.offsetParent!=null) offset+=getLeft(e.offsetParent); 
	return offset; 
} 
